package com.bwie.equipment.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.bwie.equipment.entity.t_equipment;
import com.bwie.equipment.entity.t_factory;
import com.bwie.equipment.entity.t_status;
import com.bwie.equipment.entity.t_type;
import com.bwie.equipment.service.EquipmentService;
import com.bwie.util.Page;
import com.opensymphony.xwork2.ActionSupport;

public class EquipmentAction extends ActionSupport{
	
	private EquipmentService equipmentService;
	
	
	private t_equipment equipment=new t_equipment();
	private t_type type=new t_type();
	private t_factory factory=new t_factory();
	private t_status status=new t_status();
	
	private List<t_equipment> equipmentList;
	private List<t_type> typeList;
	private List<t_factory> factoryList;
	private List<t_status> statusList;
	
	private Page page;
	private int flag;
	
	public EquipmentService getEquipmentService() {
		return equipmentService;
	}
	public void setEquipmentService(EquipmentService equipmentService) {
		this.equipmentService = equipmentService;
	}
	public t_equipment getEquipment() {
		return equipment;
	}
	public void setEquipment(t_equipment equipment) {
		this.equipment = equipment;
	}
	public t_type getType() {
		return type;
	}
	public void setType(t_type type) {
		this.type = type;
	}
	public t_factory getFactory() {
		return factory;
	}
	public void setFactory(t_factory factory) {
		this.factory = factory;
	}
	public t_status getStatus() {
		return status;
	}
	public void setStatus(t_status status) {
		this.status = status;
	}
	public List<t_equipment> getEquipmentList() {
		return equipmentList;
	}
	public void setEquipmentlList(List<t_equipment> equipmentList) {
		this.equipmentList = equipmentList;
	}
	public List<t_type> getTypeList() {
		return typeList;
	}
	public void setTypeList(List<t_type> typeList) {
		this.typeList = typeList;
	}
	public List<t_factory> getFactoryList() {
		return factoryList;
	}
	public void setFactoryList(List<t_factory> factoryList) {
		this.factoryList = factoryList;
	}
	public List<t_status> getStatusList() {
		return statusList;
	}
	public void setStatusList(List<t_status> statusList) {
		this.statusList = statusList;
	}
	public Page getPage() {
		return page;
	}
	public void setPage(Page page) {
		this.page = page;
	}
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	//**********************model end**************************************************
	
	//到页面
	public void toAdd(){
		System.out.println("-----toAdd业务----------------");
		HttpServletRequest request = ServletActionContext.getRequest();
		//得到列表，装载数据
		typeList=equipmentService.gettypeList();
		factoryList=equipmentService.getfactoryList();
		statusList=equipmentService.getstatusList();
		
		//跳转
		request.getSession().setAttribute("typeList_a", typeList);
		request.getSession().setAttribute("factoryList_a", factoryList);
		request.getSession().setAttribute("statusList_a", statusList);
		//return "toAdd";
	}
	//到页面
	public void toUpdate(){
		System.out.println("-----toUpdate业务----------------");
		HttpServletRequest request = ServletActionContext.getRequest();
		//得到列表，装载数据
		equipment=equipmentService.getEquipmentByid(equipment);
		
		typeList=equipmentService.gettypeList();
		factoryList=equipmentService.getfactoryList();
		statusList=equipmentService.getstatusList();
		
		request.getSession().setAttribute("equipment_a", equipment);
		request.getSession().setAttribute("typeList_a", typeList);
		request.getSession().setAttribute("factoryList_a", factoryList);
		request.getSession().setAttribute("statusList_a", statusList);
		//跳转
		//return "toUpdate";
	}
	
	
	//添加
	public String addEquipment(){
		System.out.println("-----addEquipment业务----------------");
		//调用业务，完成添加
		equipmentService.addEquipment(equipment);
		//跳转
		return "SUCCESS";
	}
	//修改
	public String updateEquipment(){
		System.out.println("-----updateEquipment业务----------------");
		//调用业务，完成修改
		equipmentService.updateEquipment(equipment);
		//跳转
		return "SUCCESS";
	}
	//删除
	public void deleteEquipment(){
		System.out.println("-----deleteEquipment业务----------------");
		//调用业务，完成删除
		equipmentService.deleteEquipment(equipment);
		//跳转
		//return "SUCCESS";
	}
	
	public String findEquipmentList(){
		System.out.println("-----findEquipmentList业务----------------");
		//得到列表，装载数据
		//得到总信息条数
		int totalCount = equipmentService.getEquipmentCount(equipment);
		
		//计算页面数据
		equipment.setTotalCount(totalCount);
		equipment.calculatePage();
		page=equipment;
		
		//得到列表，装载数据
		equipmentList = equipmentService.getEquipmentList(equipment);
		
		
		//跳转
		if(flag==1){
			return "ajaxPage";	
		}else{
			return "list";	
		}
	}
	
}
